<!-- 会员中心主内容区 -->
<header class="bg-red">
    <div class="a-bar" >
        <a href="javascript:history.back()" class="a-back">
            <i class="arr left"></i>
            返回
        </a>
        <div class="a-name">
            收件箱
        </div>
    </div>
</header>

<div class="page-article">
  <!-- 站内信：收件箱 -->
  <div id="member_messagebox" class="member-messagebox">
    <div class="member-tabs">
      <a href="<{link app=b2c ctl=wap_member act=inbox}>" class="active" style="color: #f48451"><span><{t}>收件箱<{/t}><{if $inbox_num!=0}>(<span class="item-unread"><{$inbox_num}></span>)<{/if}></></a>
      <a href="<{link app=b2c ctl=wap_member act=track}>"><span><{t}>发件箱<{/t}></></a>
      <a href="<{link app=b2c ctl=wap_member act=outbox}>"><span><{t}>草稿箱<{/t}><{if $outbox_num!=0}>(<span class="item-unread"><{$outbox_num}></span>)<{/if}></></a>
      <a href="<{link app=b2c ctl=wap_member act=message}>"><span><{t}>问题反馈<{/t}></></a>
    </div>
    <div class="member-mod member-messagebox-list">
      <table class="member-grid">
        <!-- 标题 -->
        <caption>
          <span class="messagebox-action"><a  class="btn btn-simple action-batch-delete"><span><span><{t}>删除<{/t}></span></span></a></span>
          <span class="messagebox-tip"><{t}>共<{/t}><i><{$total_msg}></i><{t}>条消息<{/t}>，<b class="item-unread"><{$inbox_num}></b> <{t}>条未读<{/t}></span>
        </caption>
        <thead>
          <tr>
            <th class="check"><input type="checkbox" name="" id="" class="x-check action-check-all"></th>
            <th><{t}>发件人<{/t}></th>
            <th><{t}>标题<{/t}></th>
            <th><{t}>时间<{/t}></th>
            <th><{t}>操作<{/t}></th>
          </tr>
        </thead>
        <{if count($message)>0}>
        <{foreach item=msg from=$message name=name}>
        <tbody<{if $smarty.foreach.name.iteration==1}> class="first"<{/if}>>
          <tr class="handle action-view-detail <{if $smarty.foreach.name.iteration==1}> first<{/if}><{if $msg.mem_read_status == 'false'}> new<{/if}>" value="<{$msg.comment_id}>">
            <td class="check"><input type="checkbox" name="delete[]" value="<{$msg.comment_id}>" id="" class="x-check op-check-all"<{if $smarty.foreach.name.first}> vtype="requiredcustom" data-validatormsg="请先选择消息后再删除"<{/if}> autocomplete="off"></td>
            <td class="adressee"><{if $msg.to_type == 1}><{t}>管理员<{/t}><{else}><{$msg.author}><{/if}></td>
            <td class="title"><{$msg.title|nl2br}></td>
            <td class="time"><{$msg.time|cdate:SDATE_STIME}></td>
            <td class="action"><a href="javascript:void(0);"><{t}>回复<{/t}></a></td>
          </tr>
          <tr class="detail-<{$msg.comment_id}>" style="display:none;" id="detail-<{$msg.comment_id}>">
            <td colspan="5">
              <p class="detail-title">收件标题：<{$msg.title|nl2br}></p>
              <p class="detail-content">收件内容：<{$msg.comment}></p>
              <div class="detail-reply">
                <form action="<{link app=b2c ctl=wap_member act=send_msg}>" method="post" class="action-reply-form">
                  <ul>
                    <input type="hidden" name='msg_to' value="<{$msg.author}>">
                    <li class="form-item"><label for="" class="form-label"><{t}>收件人<{/t}>：</label><span class="form-act"><{$msg.author}></span></li>
                    <li class="form-item"><label for="for_msg_title" class="form-label"><{t}>标题<{/t}>：</label><span class="form-act"><input type="text" name="subject" id="for_msg_title" class="x-input" value="Re:<{$msg.title}>" vtype="required"></span></li>
                    <li class="form-item"><label for="for_msg_content" class="form-label"><{t}>内容<{/t}>：</label><span class="form-act"><textarea name="comment" id="for_msg_content" class="x-input" cols="50" rows="5" vtype="required"></textarea></span></li>
                    <li class="form-item">
                      <span class="form-act">
                        <button type="submit" class="btn btn-caution action-sendmsg" rel="_request"><span><span><{t}>发送<{/t}></span></span></button>
                        <button type="submit" class="btn btn-simple action-savetodrafts" name="has_sent" value="false" rel="_request"><span><span><{t}>保存到草稿箱<{/t}></span></span></button>
                      </span>
                    </li>
                  </ul>
                </form>
              </div>
            </td>
          </tr>
        </tbody>
        <{/foreach}>
        <{else}>
        <tbody>
          <tr class="first"><td colspan="5" class="no-information"><{t}>暂无消息<{/t}></td></tr>
        </tbody>
        <{/if}>
      </table>
    </div>
    <{pagers data=$pager}>
  </div>
</div>

<{if count($message)>0}>
<script>
$(".action-check-all").click(function(){   
        $(".op-check-all").prop("checked", this.checked);  
});


$(".action-batch-delete").click(function(e){ 

var ischecked=false;
var deletedata;
$('.op-check-all').each(function(){
    // alert($(this).attr('checked'));
            if($(this).attr('checked')){
                ischecked=true;
            }
        });


if(ischecked===false)
    popup('请先选择消息后再删除'); 
else
{
    if(confirm('确定要删除消息吗？'))
    {
        
            $('.op-check-all').each(function(){
            if($(this).attr('checked')){
                $.post('<{link app=b2c ctl=wap_member act=deleteMsg}>','delete='+$(this).attr('value'),function(re){
                     });
                
            }
        });
           
    }
window.location.href='<{link app=b2c ctl=wap_member act=inbox }>';
}
    

});


$(".action-view-detail").click(function(e){ 

  var detail=document.getElementById('detail-'+$(this).attr('value'));
  if(detail.style.display==="none")
  {
    detail.style.display="";
  }
  else
  {
    detail.style.display="none";
  }
  
});

// $(".action-sendmsg").click(function(e){ 

//   var detail=document.getElementById('detail-'+$(this).attr('value'));
//   detail.style.display="none";
// });


// $(".action-savetodrafts").click(function(e){ 

//   var detail=document.getElementById('detail-'+$(this).attr('value'));
//   detail.style.display="none";
// });

// $('member_messagebox').addEvents({
//     'click:relay(.action-sendmsg)': function (e) {
//         var hidden = $('action_submit_save');
//         if(hidden) hidden.value = '';
//     },
//     'click:relay(.action-savetodrafts)': function (e) {
//       alert(11111);
//         $('action_submit_save') || new Element('input#action_submit_save[type=hidden]', {name: this.name, value: getValue(this)}).inject(this, 'after');
//     }
// });
function getValue(el) {
    /* <ltIE9> */
    var pollutesGetAttribute = (function(div){
      div.random = 'attribute';
      return (div.getAttribute('random') == 'attribute');
    })(document.createElement('div'));
    /* </ltIE9> */
    return pollutesGetAttribute ? el.getAttributeNode('value').nodeValue : el.get('value');
}

function popup(msg) {
    var tpl = $('<div class="popup">' + msg + '</div>').appendTo(document.body);
    var timer = setTimeout(function(){
        tpl.remove();
    }, 3000);
}
</script>
<{/if}>
